package com.ctosb.classviewer.clazz.attr;

import com.ctosb.classviewer.ClassReader;
import com.ctosb.classviewer.clazz.AbstractParse;
import com.ctosb.classviewer.clazz.Parseable;
import com.ctosb.classviewer.clazz.cp.CONSTANT_Utf8_info;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(chain = true)
public class Element_value_pair extends AbstractParse {

    private short element_name_index;
    private Element_value value;

    @Override
    public Element_value_pair parse(ClassReader classReader) {
        element_name_index = classReader.readShort();
        value = new Element_value().parse(classReader, getClassFile());
        return this;
    }

    /**
     * 字段描述符
     * @Author alan
     * @Date 2020/12/20 11:21 下午
     * @return
     */
    public String getElement_name() {
        return ((CONSTANT_Utf8_info)getClassFile().getConstant_pool()[element_name_index]).getValue();
    }
}